<?php
class Control_ServerList_checkServerId {
 	function checkServerId() {
 		$s_id = MooForm::request('s_id');
 		$id 	= MooForm::request('id');
 		
 		// 服名称
 		$serverName = array(
 			'qmby' => '霸业',
 		);
 		
 		if(empty($s_id)) {
 			$return['code'] = 2;
 			$return['msg']  = "s_id不存在,请联系管理员";
 			$this->backMsg($return);
 		}

 		$ServerlistDao = MooDao::get('Serverlist');
 		$ServerlistObj = $ServerlistDao->load($s_id);
 		if(!$ServerlistObj) {
 			$return['code'] = 3;
 			$return['msg']  = "保存失败,未s_id不存在";
 			$this->backMsg($return);
 		}
 		
 		$serverlistCfg 	= $ServerlistObj->s_serverlist;
 		$fileName 		= $ServerlistObj->s_filename;
 		$game 			= $ServerlistObj->s_game;
 		$platform 		= $ServerlistObj->s_platform;
 		
 		// 不存在通过
 		if(!$serverlistCfg) {
 			$return['code'] = 1;
 			$return['msg']  = "ok";
 			$return['name']  = $serverName[$game];
 			$this->backMsg($return);
 		}
 		
 		// 解析$serverlistCfg
 		$serverlistArr = MooJson::decode($serverlistCfg);
 		$servers = $serverlistArr['severs'];
 		
 		if(!empty($servers)) {
 			$servers_ids = array();
 			foreach ($servers as $key => $val) {
 				$servers_ids[] = $val['id'];
 			}
 			
 			// 已有的是修改
 			if(in_array($id, $servers_ids)) {
 				$return['code'] = 4;
 				$return['msg']  = "该服id已存在,请更换服id";
 				$this->backMsg($return);
 			}
 		}
 		
 		$return['code'] = 1;
 		$return['msg']  = "ok";
 		$return['name']  = $serverName[$game];
 		$this->backMsg($return);
 		
	}
	
	private function backMsg($return) {
		exit(json_encode($return));
	}
}
